package com.ma.servlet;

import com.ma.utils.Constant;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object user_session = req.getSession().getAttribute(Constant.User_SESSION);

        if (user_session!=null){
            //证明还在登录态
            req.getSession().removeAttribute(Constant.User_SESSION);
            resp.sendRedirect("/Login.jsp");

        }else{
            //没有用户在登录态
            resp.sendRedirect("/Login.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
